package service.impl;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import service.UserService;

import javax.annotation.Resource;

@Service("userService")
public class UserServiceImpl implements UserService {
    public UserDao getDao() {
        return dao;
    }

    public void setDao(UserDao dao) {
        this.dao = dao;
    }

    //只声明接口类型引用
    @Qualifier("userDao")
    @Autowired(required = false)

    @Resource(type = UserDaoImpl.class)
    private UserDao dao;
    //无参构造
    public UserServiceImpl(){}
    //用于为dao属性赋值的构造方法
    public UserServiceImpl(UserDao dao){
        this.dao = dao;
    }

    /**
     * 保存用户信息
     * @param user
     */
    @Override
    public void save(User user) {
        //调用UserDao的方法保存用户信息
        dao.save(user);
    }


    public void setDao(UserDaoImpl dao) {
    }
}
